#include "Common.h"
#include "CGShader.h"
#include "CGShaderProgram.h"
#include "Graphics/Effect.h"
#include "Cg/cgGL.h"

void RayFrame::CGShader::internalCreate()
{
  if(m_type == Shader::VERTEX_SHADER)
  {
    m_cgProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
    m_cgProgram = cgCreateProgram(
      CGEffect::GetCGContext(),
      CG_SOURCE,
      m_source.c_str(),
      m_cgProfile,
      "vs_main", NULL);
  }
  else
  {
    m_cgProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
    m_cgProgram = cgCreateProgram(
      CGEffect::GetCGContext(),
      CG_SOURCE,
      m_source.c_str(),
      m_cgProfile,
      "ps_main", NULL);
  }
  
  CGShaderProgram::CheckError();
  if(m_cgProgram)
    cgGLLoadProgram(m_cgProgram);
}

void RayFrame::CGShader::internalDestroy()
{
  cgGLLoadProgram(m_cgProgram);
  cgDestroyProgram(m_cgProgram);
  CGShaderProgram::CheckError();
}

RayFrame::CGShader::CGShader()
{

}
